﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.CampaignTime
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System;
using System.Collections.Generic;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem
{
  public struct CampaignTime : IComparable<CampaignTime>
  {
    public const int SunRise = 2;
    public const int SunSet = 22;
    public const int MinutesInHour = 60;
    public const int HoursInDay = 24;
    public const int DaysInWeek = 7;
    public const int WeeksInSeason = 3;
    public const int SeasonsInYear = 4;
    public const int DaysInSeason = 21;
    public const int DaysInYear = 84;
    internal const long TimeTicksPerMillisecond = 10;
    internal const long TimeTicksPerSecond = 10000;
    internal const long TimeTicksPerMinute = 600000;
    internal const long TimeTicksPerHour = 36000000;
    internal const long TimeTicksPerDay = 864000000;
    internal const long TimeTicksPerWeek = 6048000000;
    internal const long TimeTicksPerSeason = 18144000000;
    internal const long TimeTicksPerYear = 72576000000;
    [SaveableField(2)]
    private readonly long _numTicks;

    public static void AutoGeneratedStaticCollectObjectsCampaignTime(
      object o,
      List<object> collectedObjects)
    {
      ((CampaignTime) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    private void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
    }

    internal static object AutoGeneratedGetMemberValue_numTicks(object o)
    {
      return (object) ((CampaignTime) o)._numTicks;
    }

    internal long NumTicks => this._numTicks;

    internal CampaignTime(long numTicks) => this._numTicks = numTicks;

    private static long CurrentTicks => Campaign.Current.MapTimeTracker.NumTicks;

    public static CampaignTime DeltaTime
    {
      get => new CampaignTime(Campaign.Current.MapTimeTracker.DeltaTimeInTicks);
    }

    private static long DeltaTimeInTicks => Campaign.Current.MapTimeTracker.DeltaTimeInTicks;

    public static CampaignTime Now => Campaign.Current.MapTimeTracker.Now;

    public static CampaignTime Never => new CampaignTime(long.MaxValue);

    public bool Equals(CampaignTime other) => this._numTicks == other._numTicks;

    public override bool Equals(object obj)
    {
      return obj != null && obj is CampaignTime other && this.Equals(other);
    }

    public override int GetHashCode() => this._numTicks.GetHashCode();

    public int CompareTo(CampaignTime other)
    {
      if (this._numTicks == other._numTicks)
        return 0;
      return this._numTicks > other._numTicks ? 1 : -1;
    }

    public static bool operator <(CampaignTime x, CampaignTime y) => x._numTicks < y._numTicks;

    public static bool operator >(CampaignTime x, CampaignTime y) => x._numTicks > y._numTicks;

    public static bool operator ==(CampaignTime x, CampaignTime y) => x._numTicks == y._numTicks;

    public static bool operator !=(CampaignTime x, CampaignTime y) => !(x == y);

    public static bool operator <=(CampaignTime x, CampaignTime y) => x._numTicks <= y._numTicks;

    public static bool operator >=(CampaignTime x, CampaignTime y) => x._numTicks >= y._numTicks;

    public bool IsFuture => CampaignTime.CurrentTicks < this._numTicks;

    public bool IsPast => CampaignTime.CurrentTicks > this._numTicks;

    public bool IsNow => CampaignTime.CurrentTicks == this._numTicks;

    public bool IsDayTime
    {
      get
      {
        int num = MathF.Floor(this.CurrentHourInDay);
        return num >= 2 && num < 22;
      }
    }

    public float CurrentHourInDay => (float) (this._numTicks % 864000000L / 10000L) / 3600f;

    public bool IsNightTime => !this.IsDayTime;

    public float ElapsedMillisecondsUntilNow
    {
      get => (float) (CampaignTime.CurrentTicks - this._numTicks) / 10f;
    }

    public float ElapsedSecondsUntilNow
    {
      get => (float) (CampaignTime.CurrentTicks - this._numTicks) / 10000f;
    }

    public float ElapsedHoursUntilNow
    {
      get => (float) (CampaignTime.CurrentTicks - this._numTicks) / 3.6E+07f;
    }

    public float ElapsedDaysUntilNow
    {
      get => (float) (CampaignTime.CurrentTicks - this._numTicks) / 8.64E+08f;
    }

    public float ElapsedWeeksUntilNow
    {
      get => (float) (CampaignTime.CurrentTicks - this._numTicks) / 6.048E+09f;
    }

    public float ElapsedSeasonsUntilNow
    {
      get => (float) (CampaignTime.CurrentTicks - this._numTicks) / 1.8144E+10f;
    }

    public float ElapsedYearsUntilNow
    {
      get => (float) (CampaignTime.CurrentTicks - this._numTicks) / 7.2576E+10f;
    }

    public float RemainingMillisecondsFromNow
    {
      get => (float) (this._numTicks - CampaignTime.CurrentTicks) / 10f;
    }

    public float RemainingSecondsFromNow
    {
      get => (float) (this._numTicks - CampaignTime.CurrentTicks) / 10000f;
    }

    public float RemainingHoursFromNow
    {
      get => (float) (this._numTicks - CampaignTime.CurrentTicks) / 3.6E+07f;
    }

    public float RemainingDaysFromNow
    {
      get => (float) (this._numTicks - CampaignTime.CurrentTicks) / 8.64E+08f;
    }

    public float RemainingWeeksFromNow
    {
      get => (float) (this._numTicks - CampaignTime.CurrentTicks) / 6.048E+09f;
    }

    public float RemainingSeasonsFromNow
    {
      get => (float) (this._numTicks - CampaignTime.CurrentTicks) / 1.8144E+10f;
    }

    public float RemainingYearsFromNow
    {
      get => (float) (this._numTicks - CampaignTime.CurrentTicks) / 7.2576E+10f;
    }

    public double ToMilliseconds => (double) this._numTicks / 10.0;

    public double ToSeconds => (double) this._numTicks / 10000.0;

    public double ToMinutes => (double) this._numTicks / 600000.0;

    public double ToHours => (double) this._numTicks / 36000000.0;

    public double ToDays => (double) this._numTicks / 864000000.0;

    public double ToWeeks => (double) this._numTicks / 6048000000.0;

    public double ToSeasons => (double) this._numTicks / 18144000000.0;

    public double ToYears => (double) this._numTicks / 72576000000.0;

    public int GetHourOfDay => (int) (this._numTicks / 36000000L % 24L);

    public int GetDayOfWeek => (int) (this._numTicks / 864000000L % 7L);

    public int GetDayOfSeason => (int) (this._numTicks / 864000000L % 21L);

    public int GetDayOfYear => (int) (this._numTicks / 864000000L % 84L);

    public int GetWeekOfSeason => (int) (this._numTicks / 6048000000L % 3L);

    public CampaignTime.Seasons GetSeasonOfYear
    {
      get => (CampaignTime.Seasons) (this._numTicks / 18144000000L % 4L);
    }

    public int GetYear => (int) (this._numTicks / 72576000000L);

    public static CampaignTime Milliseconds(long valueInMilliseconds)
    {
      return new CampaignTime(valueInMilliseconds * 10L);
    }

    public static CampaignTime MillisecondsFromNow(long valueInMilliseconds)
    {
      return new CampaignTime(CampaignTime.CurrentTicks + valueInMilliseconds * 10L);
    }

    public static CampaignTime Seconds(long valueInSeconds)
    {
      return new CampaignTime(valueInSeconds * 10000L);
    }

    public static CampaignTime SecondsFromNow(long valueInSeconds)
    {
      return new CampaignTime(CampaignTime.CurrentTicks + valueInSeconds * 10000L);
    }

    public static CampaignTime Minutes(long valueInMinutes)
    {
      return new CampaignTime(valueInMinutes * 600000L);
    }

    public static CampaignTime MinutesFromNow(long valueInMinutes)
    {
      return new CampaignTime(CampaignTime.CurrentTicks + valueInMinutes * 600000L);
    }

    public static CampaignTime Hours(float valueInHours)
    {
      return new CampaignTime((long) ((double) valueInHours * 36000000.0));
    }

    public static CampaignTime HoursFromNow(float valueInHours)
    {
      return new CampaignTime(CampaignTime.CurrentTicks + (long) ((double) valueInHours * 36000000.0));
    }

    public static CampaignTime Days(float valueInDays)
    {
      return new CampaignTime((long) ((double) valueInDays * 864000000.0));
    }

    public static CampaignTime DaysFromNow(float valueInDays)
    {
      return new CampaignTime(CampaignTime.CurrentTicks + (long) ((double) valueInDays * 864000000.0));
    }

    public static CampaignTime Weeks(float valueInWeeeks)
    {
      return new CampaignTime((long) ((double) valueInWeeeks * 6048000000.0));
    }

    public static CampaignTime WeeksFromNow(float valueInWeeks)
    {
      return new CampaignTime(CampaignTime.CurrentTicks + (long) ((double) valueInWeeks * 6048000000.0));
    }

    public static CampaignTime Years(float valueInYears)
    {
      return new CampaignTime((long) ((double) valueInYears * 72576000000.0));
    }

    public static CampaignTime YearsFromNow(float valueInYears)
    {
      return new CampaignTime(CampaignTime.CurrentTicks + (long) ((double) valueInYears * 72576000000.0));
    }

    public static CampaignTime Zero => new CampaignTime(0L);

    public static CampaignTime operator +(CampaignTime g1, CampaignTime g2)
    {
      return new CampaignTime(g1._numTicks + g2._numTicks);
    }

    public static CampaignTime operator -(CampaignTime g1, CampaignTime g2)
    {
      return new CampaignTime(g1._numTicks - g2._numTicks);
    }

    public bool StringSameAs(CampaignTime otherTime)
    {
      return this._numTicks / 864000000L == otherTime.NumTicks / 864000000L;
    }

    public override string ToString()
    {
      int getYear = this.GetYear;
      CampaignTime.Seasons getSeasonOfYear = this.GetSeasonOfYear;
      int num = this.GetDayOfSeason + 1;
      TextObject text = GameTexts.FindText("str_date_format");
      text.SetTextVariable("SEASON", GameTexts.FindText("str_season_" + (object) getSeasonOfYear));
      text.SetTextVariable("YEAR", getYear.ToString());
      text.SetTextVariable("DAY", num.ToString());
      return text.ToString();
    }

    public enum Seasons
    {
      Spring,
      Summer,
      Autumn,
      Winter,
    }
  }
}
